package com.guagua.blog.controller;

import com.guagua.blog.service.LikeService;
import com.guagua.common.response.Result;
import com.guagua.system.security.SecurityUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "点赞管理", description = "点赞相关接口")
@RestController
@RequestMapping("/api/likes")
@RequiredArgsConstructor
public class LikeController {
    
    private final LikeService likeService;
    
    @Operation(summary = "点赞/取消点赞")
    @PostMapping("/{articleId}")
    public Result<Boolean> toggleLike(@Parameter(description = "文章ID") @PathVariable Long articleId) {
        Long userId = SecurityUtils.getCurrentUserId();
        boolean isLiked = likeService.toggleLike(articleId, userId);
        return Result.success(isLiked);
    }
    
    @Operation(summary = "检查是否已点赞")
    @GetMapping("/{articleId}")
    public Result<Boolean> isLiked(@Parameter(description = "文章ID") @PathVariable Long articleId) {
        Long userId = SecurityUtils.getCurrentUserId();
        boolean isLiked = likeService.isLiked(articleId, userId);
        return Result.success(isLiked);
    }
} 